<?php

class Content_Controller_Default extends MVC_AbstractController
{
	private $model;
	
	public function __construct()
	{
		
		parent::__construct();
		
		$this->model = new Content_Model_Default();
	} 
	 
    public function index()
    {
		
		return $this->model->indexPageContent();
	
    }
	
	public function getContentData($column = 'txt', $menuId = '')
	{
		
        $urlArray   = explode('/',Util::getUrl('page'));

        $contentId  = $urlArray[count($urlArray) - 2];
		
		$menuId = empty($menuId) ? $contentId : $menuId;

		$row = $this->model->getMenuContentById($menuId);
		
		if(!empty($row))
		{
			$html = '';
			//var_dump($row);
			Config::set('header_title',$row['page_title']);
			
			Config::append('assets.extras',array('<meta name="keywords" content="'.$row['keywords'].'">'));
			
			$html = $column == 'txt' ? stripslashes($row['txt']) : stripslashes($row['image']);
		
			return $html;
		}
	
	}
	
	public static function heroScoller()
	{
		$model = new Content_Model_Default();
		
		$baseUrl = Config::get('template.url').'/Default';
		
		$html = '<div class="slider_wrapper">';
		
		$html .= 	'<div class="slide">';
		
		$html .= 		'<div class="main_slideshow">';
	
		if(Util::isHomepage())
		{
			$html .= 			'<a href="'.Config::get('app.url').'/content/71/hosting"><img src="'.$baseUrl.'/images/banner3.png" alt="Professional Website Hosting" /></a>';
			$html .= 			'<a href="'.Config::get('app.url').'/content/87/seo"><img src="'.$baseUrl.'/images/banner2.png" alt="" /></a>';
			$html .= 			'<a href="'.Config::get('app.url').'"><img src="'.$baseUrl.'/images/banner1.png" alt="" /></a>';
		}
		else
		{
			$self = new Content_Controller_Default();
			
			$urlArray   = explode('/',Util::getUrl('page'));
			
       		$contentId  = $urlArray[count($urlArray) - 2];

			//$img = $self->getContentData('img', $contentId);
			//echo $baseUrl;
			//style="position: absolute; top: 0px; left: 0px; display: none; z-index: 3; opacity: 0; width: 940px; height: 288px;"
			$html .= 		'<a href="#" style="left:0; top:0; margin:0; display:block;">';
			$html .= 			'<img src="'.$baseUrl.'/images/'.$img.'" alt="" /></a>';
			$html .= 		'</a>';
		}
		$html .= 		'</div>';
		$html .= 	'</div>';
		$html .= '</div>';
		$html .= '<div class="shadow"><img src="'.$baseUrl.'/images/dropShadow958.png" alt="" /></div>';
		return $html;
	}
	
	public static function menu($position = 'H', $setId = false)
	{
		$model = new Content_Model_Default();
		
		$result = $model->menu($position = 'H');
		
		$SetupId = $setId == true ? ' id="'.$position.'_nav"' : NULL;
		
		$html = '<ul class="'.$position.'_nav"'.$SetupId.'>';
		while($row = $result->fetch(PDO::FETCH_ASSOC))
		{
			if(empty($row['nav']))
			{
				$moduleName =  'content';
				$linking = '/'.$row['id'].'/'.$row['permalink'];
			}
			else
			{
				$moduleName = $row['nav'];
				//$linking = '/'.$row['id'].'/'.$row['permalink'];
				$linking = '/'.$row['permalink'];
			}
			$link = $row['home_page'] == 'Y' ? Config::get('app.url') : Config::get('app.url').'/'.$moduleName.$linking ;
			$html .= '<li><a href="'.$link.'">'.$row['menu_title'].'</a>';
			if($setId) $html .= self::subMenu($row['id'], $position);
			$html .= '</li>';
		}
		
		$html .= '<ul>';
		
		return $html;
	}
	
	public static function subMenu($parentId, $position)
	{
		$model = new Content_Model_Default();
		
		$result = $model->subMenu($parentId);
		$count = 0;
		
		if($position == 'H')
		{
			$html = '<div class="dropdown_1column align_right">';
			$html .= 	'<ul class="greybox">';
			while($row = $result->fetch(PDO::FETCH_ASSOC))
			{
				$link =  Config::get('app.url').'/content/'.$row['id'].'/'.$row['permalink'] ;
				$html .= 	'<li><a href="'.$link.'">'.str_replace(' ', '&nbsp;', strtoupper($row['menu_title'])).'</a></li>';
				$count++;
			}
			$html .= 	'</ul>';
			$html .= '<div>';
		}
		if($count > 0 )return $html;
	}
	
}
